/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cbsrs.utils;

/**
 *
 * @author a0284024
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.apache.log4j.Logger;
//import java.sql.Statement;

public abstract class  ConnectionDAO {
private static final Logger log = Logger.getLogger(ConnectionDAO.class);
    private static Connection connection;
//    private static Statement stmt;

    public static Connection getConnectionObject() {
        String userName = "root";
        String password = "godhelp";
        String url = "jdbc:mysql://localhost:3306/cbsrs_database";
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            log.fatal(e);
        }
        try {
            connection = DriverManager.getConnection(url, userName, password);
        } catch (SQLException e) {
            log.fatal(e);
        }
        if (connection != null) {
            return connection;
        }
        return null;
    }

//    public static Statement createStatement(Connection con) {
//        try {
//            stmt = con.createStatement();
//            if (stmt != null) {
//                return stmt;
//            }
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        System.out.println("Statement has null");
//        return null;
//    }

//    public static boolean executeUpdate(Statement stm, String sql) {
//        try {
//            stm.execute(sql);
//            return true;
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//        return false;
//    }

    public static boolean closeConnection(Connection conn) {
        boolean result = false;
        try {
            conn.close();
            result = true;
        } catch (SQLException e) {
            log.fatal(e);
        }
        return result;
    }
    
}
